package au.com.mason.propertyTracker.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import au.com.mason.propertyTracker.domain.Suburb;
import au.com.mason.propertyTracker.dto.Report;

public class ReportRowMapper implements RowMapper {

	private SuburbDAO suburbDAO;
	
	public ReportRowMapper(SuburbDAO suburbDAO) {
		this.suburbDAO = suburbDAO;
	}
	
	@Override
	public Object mapRow(ResultSet resultSet, int arg1) throws SQLException {
		Suburb suburb = (Suburb) suburbDAO.findById(resultSet.getInt("suburbid"));
		Report report = new Report(suburb, 
									resultSet.getString("monthRequired"),
									resultSet.getBigDecimal("monthNumber"),
									resultSet.getBigDecimal("yearRequired"),
									resultSet.getBigDecimal("numberBedrooms"),
									resultSet.getBigDecimal("new_prop"),
									resultSet.getBigDecimal("new_prop_w_price"),
									resultSet.getBigDecimal("sold_prop"),
									resultSet.getBigDecimal("avg_on_market"),
									resultSet.getBigDecimal("avg_prop"),
									resultSet.getBigDecimal("new_rent"),
									resultSet.getBigDecimal("sold_rent"),
									resultSet.getBigDecimal("avg_rent_on_market"),
									resultSet.getBigDecimal("avg_rent"));
		return report;
	}

}
